<?php

namespace App\Library\Logic;

use App\Library\Requests\Base\BasePageRequest;
use App\Models\AddressModel;
use Illuminate\Support\Facades\DB;

class AddressLogic extends AddressModel
{
    public function paging(BasePageRequest $request): array
    {
        return paginate(self::query()->where([
            'user_id' => USERID,
            'is_return' => 0
        ])
            ->orderByDesc('id')
            ->paginate($request->limit, [
                'id',
                'user_id',
                'contacts',
                'mobile',
                'province_id',
                'city_id',
                'district_id',
                'province',
                'city',
                'district',
                'address',
                'full_address',
                'is_default',
            ])
        );
    }

    /**
     * getReturnAddress
     * @param int $userId
     * @return array
     */
    public static function getReturnAddress(int $userId): array
    {
        return self::query()->where(['user_id' => $userId, 'is_return' => 1, 'is_default' => 1])->pluck(
            DB::raw("concat(contacts,'/',mobile,'/',full_address)"), 'id'
        )->toArray();
    }
}
